package net.fei.scan.quick.util

/**
 *Create by Xianban
 *2023/11/13 10:28
 */

import com.tencent.mmkv.MMKV

object mmkv {
    // Use the default MMKV ID
    private val mmkv: MMKV by lazy {
        MMKV.defaultMMKV()
    }

    // Save String value to MMKV
    fun saveString(key: String, value: String) {
        mmkv.encode(key, value)
    }

    // Get String value from MMKV
    fun getString(key: String, defaultValue: String = ""): String {
        return mmkv.decodeString(key, defaultValue) ?: defaultValue
    }

    // Save Int value to MMKV
    fun saveInt(key: String, value: Int) {
        mmkv.encode(key, value)
    }

    // Get Int value from MMKV
    fun getInt(key: String, defaultValue: Int = 0): Int {
        return mmkv.decodeInt(key, defaultValue)
    }

    // Save Boolean value to MMKV
    fun saveBoolean(key: String, value: Boolean) {
        mmkv.encode(key, value)
    }

    // Get Boolean value from MMKV
    fun getBoolean(key: String, defaultValue: Boolean = false): Boolean {
        return mmkv.decodeBool(key, defaultValue)
    }

    // Remove a key from MMKV
    fun removeKey(key: String) {
        mmkv.removeValueForKey(key)
    }

    // Clear all keys from MMKV
    fun clearAll() {
        mmkv.clearAll()
    }
}
